package com.cta.view.model;

import java.util.HashMap;
import java.util.Map;

import org.joda.time.DateTime;
import org.joda.time.LocalTime;
import org.joda.time.Period;

import com.cta.constant.ProfileUserMapping;
import com.cta.entity.Profile;
import com.cta.view.model.discount.DiscountModel;

public class CallData {

	private String pbxId;

	private Map<String, Object> data;

	private Map<String, DiscountModel> dayDiscounts;

	private Map<String, DiscountModel> hourDiscounts;

	private DateTime startDate;

	private DateTime endDate;

	private String disountType;
	
	private String rawData;
	
	private long durationTime;

	public CallData(String rawData) {
		this.rawData = rawData;
		this.data = new HashMap<String, Object>();
		this.dayDiscounts = new HashMap<String, DiscountModel>();
		this.hourDiscounts = new HashMap<String, DiscountModel>();
	}

	public boolean hasDiscount() {
		if (this.dayDiscounts.size() > 0 || this.hourDiscounts.size() > 0) {
			return true;
		}
		return false;
	}

	public boolean hasOnlyDayDiscount() {
		if (this.dayDiscounts.size() > 0 && this.hourDiscounts.size() == 0) {
			return true;
		}
		return false;
	}

	public boolean hasOnlyHoursDiscount() {
		if (this.dayDiscounts.size() == 0 && this.hourDiscounts.size() > 0) {
			return true;
		}
		return false;
	}

	public void addData(String key, Object val) {
		data.put(key, val);
	}

	/**
	 * will using column mapping if it exits
	 * 
	 * @param profile
	 * @param val
	 */
	public void addData(Profile profile, Object val) {
		if (profile.getColumnMapping() != null) {
			data.put(profile.getColumnMapping().name(), val);
		} else {
			data.put(profile.getColumn(), val);
		}
	}

	public String getTrunkId() {
		return (String) data.get(ProfileUserMapping.def_trunk_no.name());
	}

	public DateTime getDate() {
		return (DateTime) data.get(ProfileUserMapping.def_start_date.name());
	}

	public LocalTime getStartTime() {
		return (LocalTime) data.get(ProfileUserMapping.def_start_time.name());
	}

	public String getDialedNumber() {
		return (String) data.get(ProfileUserMapping.def_dialed_number.name());
	}

	public Period getDuration() {
		return (Period) data.get(ProfileUserMapping.def_duration.name());
	}

	public String getCallingNumber() {
		return (String) data.get(ProfileUserMapping.def_calling_number.name());
	}

	public String getEmployeeCode() {
		return (String) data.get(ProfileUserMapping.def_author_code.name());
	}

	public Map<String, DiscountModel> getDayDiscounts() {
		return dayDiscounts;
	}

	public void setDayDiscounts(Map<String, DiscountModel> dayDiscounts) {
		this.dayDiscounts = dayDiscounts;
	}

	public Map<String, DiscountModel> getHourDiscounts() {
		return hourDiscounts;
	}

	public void setHourDiscounts(Map<String, DiscountModel> hourDiscounts) {
		this.hourDiscounts = hourDiscounts;
	}

	public DateTime getStartDate() {
		return startDate;
	}

	public void setStartDate(DateTime startDate) {
		this.startDate = startDate;
	}

	public DateTime getEndDate() {
		return endDate;
	}

	public void setEndDate(DateTime endDate) {
		this.endDate = endDate;
	}

	@Override
	public String toString() {
		StringBuilder bf = new StringBuilder();
		for (String key : this.data.keySet()) {
			bf.append(key).append(" : " + this.data.get(key) + " ");
		}
		return bf.toString();
	}

	public String getDisountType() {
		return disountType;
	}

	public void setDisountType(String disountType) {
		this.disountType = disountType;
	}

	public String getPbxId() {
		return pbxId;
	}

	public void setPbxId(String pbxId) {
		this.pbxId = pbxId;
	}
	
	public Map<String, Object> getData() {
		return data;
	}

	public String getRawData() {
		return rawData;
	}

	public void setRawData(String rawData) {
		this.rawData = rawData;
	}

	public long getDurationTime() {
		return durationTime;
	}

	public void setDurationTime(long durationTime) {
		this.durationTime = durationTime;
	}
}
